/*
 * BasicTypes.h
 *
 *  Created on: 10.08.2011
 *      Author: Blinov Kirill
 *   Copyright: LGPL
 *
 */
#ifndef BASICTYPES_H_
#define BASICTYPES_H_

#include <stdint.h>
#include <stddef.h>
#include <stdio.h>

// TODO Задефайнить типы, как говорил Филёк. Вот он этим и займётся))
//typedef int   __int32
//typedef short	__int16

/*
 * Network message sructure described in Сетевой протокол.odt
 */
struct NETWORK_MESSAGE_HEADER
{
	NETWORK_MESSAGE_HEADER(): size(0), version(0), group(0), value(0), clientId(0), additionalData1(0),
			additionalData2(0)
	{};
	NETWORK_MESSAGE_HEADER( size_t Size, unsigned char Version, unsigned char Group, unsigned char Value, unsigned char ClientId ):
		size(Size), version(Version), group(Group), value(Value), clientId(ClientId), additionalData1(0),
		additionalData2(0)
	{
		size = Size;
		version = Version;
		group = Group;
		value = Value;
	}
	size_t size;    // Size of data
	unsigned char   version; // protocol version
	 unsigned char   group: 2; // 2 bits
	 unsigned char   value: 6; // 6 bits
	unsigned char   clientId;
	unsigned int   additionalData1;
	unsigned int   additionalData2;
};

struct STANDART_NETWORK_MESSAGE
{
	STANDART_NETWORK_MESSAGE():
		 data( NULL ), header( 0, 0, 0, 0, 0 )
	{
	};
	STANDART_NETWORK_MESSAGE( unsigned char Version, unsigned char Group, unsigned char Value, unsigned char ClientId ):
		data( NULL ), header( 0, Version, Group, Value, ClientId )
	{
	};
	STANDART_NETWORK_MESSAGE( unsigned char Version, unsigned char Group, unsigned char Value, unsigned char ClientId, unsigned char* Data, size_t DataSize ):
			data( Data ), header( DataSize, Version, Group, Value, ClientId )
	{
	};
	~STANDART_NETWORK_MESSAGE()
	{
		if ( data != NULL )
			delete data;
	};
	NETWORK_MESSAGE_HEADER header;
	unsigned char* data;
};

#endif /* BASICTYPES_H_ */
